package com.ymttest.business.service;

import com.google.gson.JsonObject;
import com.ymatou.iapi.productimporter.parameter.TaobaoZhuShouExportBean;
import com.ymatou.iapi.productimporter.parameter.YMTExportBean;
import com.ymatou.iapi.productmanager.parameter.*;
import com.ymatou.iapi.productmanager.parameter.product.*;
import com.ymatou.iapi.productmanager.service.*;
import com.ymatou.iapi.productsync.parameter.MongocrudBean;
import com.ymatou.iapi.productsync.service.MongocrudCall;
import com.ymatou.iapi.productsynces.parameter.ESBean;
import com.ymatou.iapi.productsynces.service.ESCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.annotation.product.IntergratedProductMapper;
import com.ymttest.database.redis.ImRedisWapper;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.ZipUtils;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;

public class ProductManagerCallServiceV3 {
	/**
	 * 测试用的固定BrandId-由于品类变动可能导致失效请查询 Ymt_ProductBrandCategory
	 */
	public static Integer BrandId=10187;
	// private static SimpleDateFormat sdf = new
	// SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
	// private static String price = "10";
	/**全球优选设置会员商品
	 * @param pid
	 * @param sellerid
	 * @param ismember
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void SetMemberProduct(String pid,Integer sellerid,boolean ismember) throws ClientProtocolException, IOException {
		SetMemberProductBean setmemberproductBean=new SetMemberProductBean();
		SetMemberProductCall setmemberproductCall=new SetMemberProductCall();
		setmemberproductBean.setMember(ismember);
		setmemberproductBean.setProductId(pid);
		
		
		setmemberproductBean.setUserId(sellerid);
		setmemberproductCall.setData(setmemberproductBean);
		setmemberproductCall.callService();			
	}
	//List<Map> list = intergratedProductMapper.selectYmtSellerProductTag
	/**
	 * 删除用户的所有指定thirdcategoryid 标签
	 * @param sellerId
	 * @param thirdcategoryid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void DeleteAllSellerPorductTags(Integer sellerId, Integer thirdcategoryid) throws ClientProtocolException, IOException {
		IntergratedProductMapper intergratedProductMapper = SqlMapperFactory.getIntergratedProductMapper();
		List<Map> list = intergratedProductMapper.selectYmtSellerProductTag(sellerId, thirdcategoryid);
		list.forEach(m->{
			Integer tagId=Integer.valueOf( m.get("Id").toString());
			try {
				DeleteSellerPorductTags(sellerId, tagId);
			} catch (IOException e) {
				e.printStackTrace();
			}
		});
	}
	/**
	 * 删除商品标签 
	 * @param sellerId 
	 * @param tagId 
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * 
	 */
	public static void DeleteSellerPorductTags(Integer sellerId, Integer tagId) throws ClientProtocolException, IOException {
		DeleteSellerPorductTagsBean deletesellerporducttagsBean=new DeleteSellerPorductTagsBean();
		DeleteSellerPorductTagsCall deletesellerporducttagsCall=new DeleteSellerPorductTagsCall();
		deletesellerporducttagsBean.setSellerId(sellerId);
		deletesellerporducttagsBean.setTagId(tagId);
		deletesellerporducttagsCall.setData(deletesellerporducttagsBean);
		deletesellerporducttagsCall.callService();
	}
	/**
	 * 添加商品标签 
	 * @param sellerId 
	 * @param tagId 
	 * @return 
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * 
	 */
	public static int AddSellerPorductTags(Integer sellerId, Integer cid,Integer tcid,String tag) throws ClientProtocolException, IOException {
		AddSellerPorductTagsBean addsellerporducttagsBean=new AddSellerPorductTagsBean();
		AddSellerPorductTagsCall addsellerporducttagsCall=new AddSellerPorductTagsCall();
		addsellerporducttagsBean.setSellerId(sellerId);
		addsellerporducttagsBean.setCategoryId(1001);
		addsellerporducttagsBean.setThirdcategoryId(1003);
		addsellerporducttagsBean.setTags(tag);
		addsellerporducttagsCall.setData(addsellerporducttagsBean);
		addsellerporducttagsCall.callService();	
		int tagid=0;
		try {
			tagid=addsellerporducttagsCall.getJsonObject().get("Data").getAsJsonObject().get("tag").getAsJsonObject().get("id").getAsInt();
		}catch (Exception e) {
		}
		return 	tagid;
	}
	public static PreGrouponProductListCall GetPreGrouponProductList(PreGrouponProductListBean preGrouponProductListBean) throws IOException {
		PreGrouponProductListCall preGrouponProductListCall = new PreGrouponProductListCall();
		preGrouponProductListCall.setData(preGrouponProductListBean);
		preGrouponProductListCall.callService();
		return preGrouponProductListCall;
	}

	/**
	 * 更新商品审核状态  	0通过，-1不通过
	 * @param productId
	 * @param auditStatus
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void  UpdateAuditStatus(String productId,int auditStatus) throws ClientProtocolException, IOException{
		UpdateAuditStatusBean updateauditstatusBean = new UpdateAuditStatusBean();
		UpdateAuditStatusCall updateauditstatusCall = new UpdateAuditStatusCall();
		updateauditstatusBean.setAuditStatus(auditStatus);
		updateauditstatusBean.setProductId(productId);
		updateauditstatusCall.setData(updateauditstatusBean);
		updateauditstatusCall.callService();			
		Logger.verifyEquals("OK", updateauditstatusCall.getReturnData(), "验证code");
	}
	/**
	 * 初始化可选商品列表bean
	 * 
	 * @param sellerId
	 * @param tab
	 *            0是可选，1是不可选商品
	 * @return
	 */
	public static PreGrouponProductListBean initPreGrouponProductList(int sellerId, int tab) {
		PreGrouponProductListBean preGrouponProductListBean = new PreGrouponProductListBean();
		preGrouponProductListBean.setSellerId(sellerId);
		preGrouponProductListBean.setProductName(null);
		preGrouponProductListBean.setTab(tab);
		preGrouponProductListBean.setThirdCategoryId(0);
		preGrouponProductListBean.setPageSize(10);
		preGrouponProductListBean.setPageIndex(1);
		return preGrouponProductListBean;
	}

	/**
	 * 获取拼团商品列表
	 * 
	 * @param grouponProductListBean
	 * @return
	 * @throws IOException
	 */
	public static GrouponProductListCall GetGrouponProductList(GrouponProductListBean grouponProductListBean) throws IOException {
		GrouponProductListCall grouponProductListCall = new GrouponProductListCall();
		grouponProductListCall.setData(grouponProductListBean);
		grouponProductListCall.callService();
		return grouponProductListCall;
	}

	/**
	 * 初始化获取拼团商品列表Bean
	 * 
	 * @param sellerId
	 * @return
	 */
	public static GrouponProductListBean initGrouponProductList(int sellerId) {
		GrouponProductListBean grouponProductListBean = new GrouponProductListBean();
		grouponProductListBean.setSellerId(sellerId);
		grouponProductListBean.setPageIndex(1);
		grouponProductListBean.setPageSize(10);
		grouponProductListBean.setProductName(null);
		grouponProductListBean.setThirdCategoryId(0);
		return grouponProductListBean;
	}

	/**
	 * 停止拼团
	 * 
	 * @param groupProductId
	 *            团商品id
	 * @return
	 * @throws IOException
	 */
	public static StopGrouponCall StopGroupon(int groupProductId) throws IOException {
		StopGrouponBean stopGrouponBean = new StopGrouponBean();
		StopGrouponCall stopGrouponCall = new StopGrouponCall();
		stopGrouponBean.setGroupProductId(groupProductId);
		stopGrouponCall.setData(stopGrouponBean);
		stopGrouponCall.callService();
		return stopGrouponCall;
	}

	/**
	 * 初始化创建拼团bean 默认创建0 没有grouponProductId 如果需要使用修改 setOperateType(1); 并且
	 * setGrouponProductId
	 * 
	 * @param pid
	 * @param grouponPrice
	 * @return
	 * @throws InterruptedException
	 */
	public static SaveGrouponBean initSaveGrouponBean(Integer sellerid, String pid, Double grouponPrice) throws InterruptedException {
		SaveGrouponBean savegrouponBean = new SaveGrouponBean();
		YmtCatalogsIWapper ymtCatalogsIWapper = new YmtCatalogsIWapper();
		List<String> catalogs = ymtCatalogsIWapper.selectCatalogsByProductId(pid).stream().map(ele -> ele.getsCatalogId()).collect(Collectors.toList());
		Logger.debug(FormatUtil.beanToGSONString(catalogs));
		List<GrouponCatalogDto> grouponCatalogs = new ArrayList<GrouponCatalogDto>();
		catalogs.forEach(catalogId -> {
			GrouponCatalogDto e = new GrouponCatalogDto();
			e.setCatalogId(catalogId);
			e.setGrouponPrice(grouponPrice);
			grouponCatalogs.add(e);
		});
		savegrouponBean.setGrouponCatalogs(grouponCatalogs);
		savegrouponBean.setOperateType(0);
		savegrouponBean.setProductId(pid);
		savegrouponBean.setSellerId(sellerid);
		return savegrouponBean;
	}

	/**
	 * 创建拼团
	 * 
	 * @param savegrouponBean
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void SaveGrouponCall(SaveGrouponBean savegrouponBean) throws ClientProtocolException, IOException {
		SaveGrouponCall savegrouponCall = new SaveGrouponCall();
		savegrouponCall.setData(savegrouponBean);
		savegrouponCall.callService();
	}

	/**
	 * 初始化商品数据
	 * 
	 * @param sellerId
	 * @return
	 */
	public static AddSellerProductRequest initAddSellerProductRequest(int sellerId) {
		AddSellerProductRequest AddSellerProductRequest = new AddSellerProductRequest();
		// 最外层
		AddSellerProductRequest.setSellerId(sellerId);
		String sellerName = new JUserWapper().selectUserinfoByUid(sellerId).get(0).getLoginId();
		AddSellerProductRequest.setSellerName(sellerName);
		AddSellerProductRequest.setProductSite("PC");
		// ProductSaveModel 外层
		ProductSaveModel productSaveModel = new ProductSaveModel();
		productSaveModel.setSellerId(sellerId);
		productSaveModel.setSellerLoginId(sellerName);
		productSaveModel.setProductType(0);
		productSaveModel.setProductName("测试山沟" + YMTDateUtil.getDate().getTime());
		productSaveModel.setLiveIdList(null);
		// 二级类目编号
		productSaveModel.setSecondCategoryId(1002);
		// 三级类目编号
		productSaveModel.setThirdCategoryId(1003);
		// 标准品牌编号
		productSaveModel.setBrandId(ProductManagerCallServiceV3.BrandId);
		// 标准品牌名称
		productSaveModel.setBrandName("耐克");
		// 商品图片列表
		/*
		 * List<String> picList = Arrays.asList(
		 * "http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg",
		 * "http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401.jpg",
		 * "http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg"
		 * );
		 */
		List<String> picList = new ArrayList<>();
		picList.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg");
		picList.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401.jpg");
		picList.add("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg");
		productSaveModel.setProductPicList(picList);
		// 物流方式
		productSaveModel.setCatalogStatus(5);
		// 测试商户当前的物流方式发布权限
		if (sellerId == 24636166) {
			productSaveModel.setCatalogStatus(3);
		}
		productSaveModel.setNoticeRisk(true);

		String validStart = YMTDateUtil.getBeforeOrNextDay(0, YMTDateUtil.YMDHMS);
		String validEnd = YMTDateUtil.getBeforeOrNextDay(7, YMTDateUtil.YMDHMS);
		// 商品的起始有效期
		productSaveModel.setValidStart(validStart);
		// 商品上架结束有效期
		productSaveModel.setValidEnd(validEnd);
		// 自动延期标识
		productSaveModel.setAutoRefresh(true);
		// 备货类型（0-现货，1-扫货，2- FBX）
		productSaveModel.setCatalogType(0);
		// 包税方式（交税方 0. 卖家交税，1. 买家交税,） default = 0 默认传 0
		productSaveModel.setTariffType(0);
		// 保税区
		productSaveModel.setBondedArea(7);
		// 保税商品备案号
		productSaveModel.setProductCode("Test" + YMTDateUtil.getDate());
		// 七天无理由退货
		productSaveModel.setNoReasonReturn(false);
		// 多物流方式（0-不支持，3-贝海直邮）
		productSaveModel.setMultiLogistics(0);
		// 多物流差价
		productSaveModel.setFlightBalance(0);
		productSaveModel.setWeightUnit(2);
		// 上架销售类型-1, 原时间 0, 立即上架 1, 定时上架 2, 发布但不上架 3, 按直播时间上架
		productSaveModel.setOnSaleType(0);
		// 来源
		productSaveModel.setSourceType("PC");
		// productSaveModel.setSellerCountryId();
		// 发布（true） & 编辑（false） 商品坑位计算使用，可不作为参数传入
		productSaveModel.setReleaseProduct(true);
		// 选填，长度限定为700个字符
		productSaveModel.setRemark("Testzhaxina" + YMTDateUtil.getDate());

		// 规格1
		CatalogSaveModel catalogSaveModel1 = new CatalogSaveModel();
		catalogSaveModel1.setOperateType(1);
		catalogSaveModel1.setPackage(false);
		catalogSaveModel1.setPreSale(false);
		catalogSaveModel1.setWeight(1);
		// 规格新客价
		String newPrice = "8";
		catalogSaveModel1.setNewPrice(Integer.valueOf(newPrice));
		// 规格vip价格
		String vipPrice = "12";
		catalogSaveModel1.setVipPrice(Integer.valueOf(vipPrice));
		// 商品原价
		String price = "16";
		catalogSaveModel1.setPrice(Integer.valueOf(price));
		// BigDecimal marketPrice = new BigDecimal(20);
		String marketPrice = "20";
		catalogSaveModel1.setMarketPrice(Integer.valueOf(marketPrice));
		catalogSaveModel1.setAction(0);
		catalogSaveModel1.setStock(1000000);
		catalogSaveModel1.setMultiLogistics(0);
		catalogSaveModel1.setSku("sku-7232f1de-ffbf-49ae-a0bc-d8765456b07f");
		catalogSaveModel1.setWeight(2);
		// 规格属性
		List<CatalogPropertySaveModel> propertyList = new ArrayList<>();
		CatalogPropertySaveModel e1 = new CatalogPropertySaveModel();
		e1.setPropertyName("颜色");
		e1.setPropertyUrl("http://s2.ymatou.com/home/b5abefb15e5afbb91d82c65df819be22.png");
		e1.setPropertyValue("红色");
		propertyList.add(e1);
		catalogSaveModel1.setPropertyList(propertyList);

		// 规格2
		CatalogSaveModel catalogSaveModel2 = new CatalogSaveModel();
		catalogSaveModel2.setOperateType(1);
		catalogSaveModel2.setPackage(false);
		catalogSaveModel2.setPreSale(false);
		// 规格新客价
		newPrice = "10";
		catalogSaveModel2.setNewPrice(Integer.valueOf(newPrice));
		// 规格vip价格
		vipPrice = "15";
		catalogSaveModel2.setVipPrice(Integer.valueOf(vipPrice));
		// 商品原价
		price = "20";
		catalogSaveModel2.setPrice(Integer.valueOf(price));
		String marketPrice1 = "30";
		catalogSaveModel2.setMarketPrice(Integer.valueOf(marketPrice1));
		catalogSaveModel2.setAction(0);
		catalogSaveModel2.setStock(1000000);
		catalogSaveModel2.setMultiLogistics(0);
		catalogSaveModel2.setSku("sku-7232f1de-ffbf-49ae-a0bc-d8765456b07f");
		// 规格属性
		List<CatalogPropertySaveModel> propertyList1 = new ArrayList<>();
		CatalogPropertySaveModel e2 = new CatalogPropertySaveModel();
		e2.setPropertyName("颜色");
		e2.setPropertyUrl("http://s2.ymatou.com/home/b5abefb15e5afbb91d82c65df819be22.png");
		e2.setPropertyValue("蓝色");
		propertyList1.add(e2);
		catalogSaveModel2.setPropertyList(propertyList1);

		List<CatalogSaveModel> catalogSaveModels = new ArrayList<>();
		catalogSaveModels.add(catalogSaveModel1);
		catalogSaveModels.add(catalogSaveModel2);
		productSaveModel.setCatalogList(catalogSaveModels);

		// 商品文描
		ProductDescSaveModel descModel = new ProductDescSaveModel();
		descModel.setDescription("商品文描");
		List<String> descPicList = new ArrayList<>();
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71a.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71c.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71d.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71e.png");
		descModel.setDescPicList(descPicList);
		descModel.setBuyerNoticeId(0);
		descModel.setDeclarationId(0);
		descModel.setSellerServiceId(0);
		descModel.setSizeTemplateId(0);
		productSaveModel.setDescModel(descModel);

		// 商品关联运费模板
		List<ProductFreightSaveModel> freightTemplateList = new ArrayList<>();
		productSaveModel.setFreightTemplateList(freightTemplateList);

		// 商品视频 null
		productSaveModel.setVideoModel(null);

		// 商品属性
		List<ProductPropertySaveModel> productPropertySaveModels = new ArrayList<>();
		ProductPropertySaveModel e = new ProductPropertySaveModel();
		e.setPropertyId(1);
		List<String> propertyValues = new ArrayList<>();
		propertyValues.add("propertyValue1");
		propertyValues.add("propertyValue2");
		e.setPropertyValues(propertyValues);
		productPropertySaveModels.add(e);
		productSaveModel.setPropertyList(productPropertySaveModels);
		//物流信息 新增20201216
		productSaveModel.setPackageDeliveryType(0);
		productSaveModel.setDeliveryAging(5);
		productSaveModel.setDeliveryCompanyType(2);
		
		AddSellerProductRequest.setProduct(productSaveModel);
		return AddSellerProductRequest;
	}

	/**
	 * 创建商品mock物流
	 * 
	 * @param addpro
	 * @return
	 * @throws IOException
	 */
	public static String AddSellerProduct(AddSellerProductRequest addpro) throws IOException {
		AddSellerProductCall addSellerProductCall = new AddSellerProductCall();
		addSellerProductCall.setData(addpro);
		//add by summing 20201223
		addSellerProductCall.addHeader("mock", "mock-enable");
	     //物流权限1
        addSellerProductCall.addHeader("mockId-1", "GUID");
        addSellerProductCall.addHeader("mockApi-1", "orderdelivery-GetAvailableDeliveryMethod-Normal");
        //物流权限2
        addSellerProductCall.addHeader("mockId-2", "GUID");
        addSellerProductCall.addHeader("mockApi-2", "orderdelivery-GetAvailableDeliveryMethodV2-Normal");
        //自动巡检
        addSellerProductCall.addHeader("mockId-3", "GUID");
        addSellerProductCall.addHeader("mockApi-3", "Violate-autoPreViolateProduct-Normal");
        //买手专项权限
        addSellerProductCall.addHeader("mockId-4", "GUID");
        addSellerProductCall.addHeader("mockApi-4", "sellerallocation-checkSellerSpecialPermission-Normal");
        //发商品的数量
		addSellerProductCall.addHeader("mockId-5", "GUID");
		addSellerProductCall.addHeader("mockApi-5", "SellerService-getSellerSeat-Normal");
			
		addSellerProductCall.callService();
		return addSellerProductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
	}

	/**
	 * 编辑商品
	 * 
	 * @param productId
	 * @param addProdReq
	 * @throws IOException
	 */
	public static void ModifySellerProduct(String productId, AddSellerProductRequest addProdReq) throws IOException {
		ModifySellerProductRequest modifyBean = AddProductCallServiceV2.getModifySellerProductRequestFromAddProductBean(productId, addProdReq);
		ModifySellerProductCall modifySellerProductCall = new ModifySellerProductCall();
		
		modifySellerProductCall.addHeader("mock", "mock-enable");
	     //物流权限1
        modifySellerProductCall.addHeader("mockId-1", "GUID");
        modifySellerProductCall.addHeader("mockApi-1", "orderdelivery-GetAvailableDeliveryMethod-Normal");
       //物流权限2
        modifySellerProductCall.addHeader("mockId-2", "GUID");
        modifySellerProductCall.addHeader("mockApi-2", "orderdelivery-GetAvailableDeliveryMethodV2-Normal");
       //自动巡检
        modifySellerProductCall.addHeader("mockId-3", "GUID");
        modifySellerProductCall.addHeader("mockApi-3", "Violate-autoPreViolateProduct-Normal");
       //买手专项权限
        modifySellerProductCall.addHeader("mockId-4", "GUID");
        modifySellerProductCall.addHeader("mockApi-4", "sellerallocation-checkSellerSpecialPermission-Normal");
       //发商品的数量
		modifySellerProductCall.addHeader("mockId-5", "GUID");
		modifySellerProductCall.addHeader("mockApi-5", "SellerService-getSellerSeat-Normal");
		
		modifySellerProductCall.setData(modifyBean);
		modifySellerProductCall.callService();
	}

	/**
	 * 商品mock
	 * @param callType 添加商品：AddSellerProductCall   修改商品:ModifySellerProductCall
	 */
	public static  void mockProduct(Object callType)
	{
		if(callType instanceof  AddSellerProductCall){
			AddSellerProductCall addSellerProductCall = (AddSellerProductCall)callType;
			 //add by summing 20201223
			 addSellerProductCall.addHeader("mock", "mock-enable");
			 //物流权限1
			 addSellerProductCall.addHeader("mockId-1", "GUID");
			 addSellerProductCall.addHeader("mockApi-1", "orderdelivery-GetAvailableDeliveryMethod-Normal");
			 //物流权限2
			 addSellerProductCall.addHeader("mockId-2", "GUID");
			 addSellerProductCall.addHeader("mockApi-2", "orderdelivery-GetAvailableDeliveryMethodV2-Normal");
			 //自动巡检
			 addSellerProductCall.addHeader("mockId-3", "GUID");
			 addSellerProductCall.addHeader("mockApi-3", "Violate-autoPreViolateProduct-Normal");
			 //买手专项权限
			 addSellerProductCall.addHeader("mockId-4", "GUID");
			 addSellerProductCall.addHeader("mockApi-4", "sellerallocation-checkSellerSpecialPermission-Normal");
			 //发商品的数量
			 addSellerProductCall.addHeader("mockId-5", "GUID");
			 addSellerProductCall.addHeader("mockApi-5", "SellerService-getSellerSeat-Normal");

		 } if(callType instanceof  ModifySellerProductCall){
			 ModifySellerProductCall modifySellerProductCall = (ModifySellerProductCall)callType;

			 modifySellerProductCall.addHeader("mock", "mock-enable");
			 //物流权限1
			 modifySellerProductCall.addHeader("mockId-1", "GUID");
			 modifySellerProductCall.addHeader("mockApi-1", "orderdelivery-GetAvailableDeliveryMethod-Normal");
			 //物流权限2
			 modifySellerProductCall.addHeader("mockId-2", "GUID");
			 modifySellerProductCall.addHeader("mockApi-2", "orderdelivery-GetAvailableDeliveryMethodV2-Normal");
			 //自动巡检
			 modifySellerProductCall.addHeader("mockId-3", "GUID");
			 modifySellerProductCall.addHeader("mockApi-3", "Violate-autoPreViolateProduct-Normal");
			 //买手专项权限
			 modifySellerProductCall.addHeader("mockId-4", "GUID");
			 modifySellerProductCall.addHeader("mockApi-4", "sellerallocation-checkSellerSpecialPermission-Normal");
			 //发商品的数量
			 modifySellerProductCall.addHeader("mockId-5", "GUID");
			 modifySellerProductCall.addHeader("mockApi-5", "SellerService-getSellerSeat-Normal");
		 }
	}
	/**
	 * 编辑商品
	 * 
	 * @param modifyBean
	 * @throws IOException
	 */
	public static void ModifySellerProduct(ModifySellerProductRequest modifyBean) throws IOException {
		ModifySellerProductCall modifySellerProductCall = new ModifySellerProductCall();
		modifySellerProductCall.setData(modifyBean);
		modifySellerProductCall.callService();
	}

	/**
	 * 初始化规格bean
	 *
	 * @return
	 */
	public static CatalogSaveModel initCatalogSaveModel() {
		CatalogSaveModel CatalogSaveModel = new CatalogSaveModel();

		CatalogSaveModel.setOperateType(1);
		CatalogSaveModel.setPackage(false);
		CatalogSaveModel.setPreSale(false);
		CatalogSaveModel.setNewPrice(Integer.valueOf("10"));
		CatalogSaveModel.setVipPrice(Integer.valueOf("15"));
		CatalogSaveModel.setPrice(Integer.valueOf("20"));
		CatalogSaveModel.setAction(0);
		CatalogSaveModel.setStock(1000000);
		CatalogSaveModel.setMultiLogistics(0);
		CatalogSaveModel.setSku("sku-7232f1de-ffbf-49ae-a0bc-d8765456b07f");

		List<CatalogPropertySaveModel> propertyList = new ArrayList<>();
		CatalogPropertySaveModel e1 = new CatalogPropertySaveModel();
		// e.setPropertyId("1");
		e1.setPropertyName("颜色" + TestDataManager.getRandomIntNum(1));
		e1.setPropertyUrl("http://s2.ymatou.com/home/b5abefb15e5afbb91d82c65df819be22.png");
		e1.setPropertyValue("色号" + TestDataManager.getRandomIntNum(2));
		propertyList.add(e1);
		CatalogSaveModel.setPropertyList(propertyList);
		return CatalogSaveModel;

	}

	/**
	 * 初始化发布微店商品bean
	 * 
	 * @param sellerId
	 * @return
	 */
	public static AddMicroProductBean initAddmicroproductBean(int sellerId) {
		AddMicroProductBean microProductBean = new AddMicroProductBean();
		microProductBean.setProductSite("PC");
		microProductBean.setReleaseProduct(true);

		WeChatProductModel weChatProductModel = new WeChatProductModel();
		weChatProductModel.setSellerId(sellerId);
		weChatProductModel.setSecondCategoryId(1002);
		weChatProductModel.setProductName("ceshi" + YMTDateUtil.getDate());
		List<String> picList = Arrays.asList("http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg",
				"http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401.jpg",
				"http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701.jpg");
		weChatProductModel.setPicUrls(picList);
		weChatProductModel.setOnSaleType(0);
		weChatProductModel.setLiveId(0);
		weChatProductModel.setFirstCategoryId(1001);
		weChatProductModel.setCatalogStatus(5);

		ProductDescSaveModel descModel = new ProductDescSaveModel();
		descModel.setDescription("商品文描");
		List<String> descPicList = new ArrayList<>();
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71a.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71c.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71d.png");
		descPicList.add("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71e.png");
		descModel.setDescPicList(descPicList);
		weChatProductModel.setProductDescModel(descModel);

		WeChatCatalogDto weChatCatalogDto1 = new WeChatCatalogDto();
		weChatCatalogDto1.setCatalogName("规格1" + YMTDateUtil.getDate());
		weChatCatalogDto1.setPicUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71b.png");
		weChatCatalogDto1.setPrice(100);
		weChatCatalogDto1.setStock(10000);

		WeChatCatalogDto weChatCatalogDto2 = new WeChatCatalogDto();
		weChatCatalogDto2.setCatalogName("规格2" + YMTDateUtil.getDate());
		weChatCatalogDto2.setPicUrl("http://s2.ymatou.com/home/4aa0780b5ffeee46a01f132052fdb71d.png");
		weChatCatalogDto2.setPrice(100);
		weChatCatalogDto2.setStock(10000);

		List<WeChatCatalogDto> catalogList = new ArrayList<>();
		catalogList.add(weChatCatalogDto1);
		catalogList.add(weChatCatalogDto2);
		weChatProductModel.setCatalogList(catalogList);
		microProductBean.setProduct(weChatProductModel);
		return microProductBean;
	}

	/**
	 * 初始化编辑微店商品bean
	 * 
	 * @param productId
	 * @param addmicroProductBean
	 * @return
	 */
	public static MicroProductBean getMicroproductBean(String productId, AddMicroProductBean addmicroProductBean) {
		MicroProductBean microProductBean = new MicroProductBean();
		microProductBean.setProductId(productId);
		microProductBean.setProduct(addmicroProductBean.getProduct());
		IntergratedProductMapper ipm = SqlMapperFactory.getIntergratedProductMapper();
		List<Map<String, Object>> maps = ipm.selectCatalogsByProdId(productId);
		for (int i = 0; i < maps.size(); i++) {
			microProductBean.getProduct().getCatalogList().get(i).setCatalogId(maps.get(i).get("sCatalogId").toString());
			microProductBean.getProduct().getCatalogList().get(i).setStock(Integer.parseInt(maps.get(i).get("iNum").toString()));
			microProductBean.getProduct().getCatalogList().get(i).setPrice(Double.valueOf(maps.get(i).get("fQuotePrice").toString()));
		}
		return microProductBean;
	}

	/**
	 * 发布微店商品
	 * 
	 * @param addMicroProductBean
	 * @return
	 * @throws IOException
	 */
	public static String Addmicroproduct(AddMicroProductBean addMicroProductBean) throws IOException {
		AddMicroProductCall microProductCall = new AddMicroProductCall();
		microProductCall.setData(addMicroProductBean);
		microProductCall.callService();
		String productId = microProductCall.getJsonObject().get("Data").getAsJsonObject().get("ProductId").getAsString();
		return productId;
	}

	/**
	 * 买手设置或者移出PSP优选
	 * 
	 * @param sellerId
	 * @param productId
	 * @param isAdd
	 */
	public static void SetPspTag(int sellerId, String productId, boolean isAdd) throws IOException {
		SetPspTagBean setPspTagBean = new SetPspTagBean();
		SetPspTagCall setPspTagCall = new SetPspTagCall();
		setPspTagBean.setProductId(productId);
		setPspTagBean.setSellerId(sellerId);
		setPspTagBean.setIsAdd(isAdd);
		setPspTagCall.setData(setPspTagBean);
		setPspTagCall.callService();
	}

	/**
	 * 运营审核PSP商品的状态
	 * 
	 * @param sellerId
	 *            买手id
	 * @param productId
	 *            商品id
	 * @param IsPassViolate
	 *            是否通过巡检
	 * @param IsRemovePsp
	 *            是否psp撤标
	 * @throws IOException
	 */
	public static void SetPspStatus(int sellerId, String productId, boolean IsPassViolate, boolean IsRemovePsp) throws IOException {
		SetPspStatusBean setPspStatusBean = new SetPspStatusBean();
		setPspStatusBean.setIsPassViolate(IsPassViolate);
		setPspStatusBean.setIsRemovePsp(IsRemovePsp);
		setPspStatusBean.setProductId(productId);
		setPspStatusBean.setSellerId(sellerId);
		SetPspStatusCall setPspStatusCall = new SetPspStatusCall();
		setPspStatusCall.setData(setPspStatusBean);
		setPspStatusCall.callService();
	}

	public static void updateProductRedisTimeStamp(String productId) throws JSONException {
		org.json.JSONObject ob = new JSONObject(new ImRedisWapper().getproductById(productId));
		ob.put("aut", new Date().getTime());
		ob.put("cut", new Date().getTime());
		ob.put("sut", new Date().getTime());
		ob.put("gut", new Date().getTime());
		String timeStamp = ob.toString();
		new ImRedisWapper().updateProductTimeStamp(productId, timeStamp);
	}

	/**
	 * 修改商品类型 优选用
	 * @param userId sellerid
	 * @param productId 商品id
	 * @param gift 1 礼包 2 优选团
	 * @throws IOException
	 */
	public static void UpdateGiftType(int userId, String productId,int gift) throws IOException {
		UpdateGiftTypeBean updateGiftTypeBean = new UpdateGiftTypeBean();
		updateGiftTypeBean.setProductId(productId);
		updateGiftTypeBean.setUserId(userId);
		updateGiftTypeBean.setGiftType(gift);
		UpdateGiftTypeCall updateGiftTypeCall = new UpdateGiftTypeCall();
		updateGiftTypeCall.setData(updateGiftTypeBean);
		updateGiftTypeCall.callService();
	}
	/**
	 * YMT格式导入数据
	 * @param title
	 * @param price 图片 ;分割
	 * @param num
	 * @param picurl
	 * @return
	 */
	public static YMTExportBean initYMTExportBean(String title, String picurl) {
		YMTExportBean ymtbean = new YMTExportBean();
//		appendString(dline, data.getTitle());
		ymtbean.setTitle(title);
//		appendString(dline, data.getPic());
		ymtbean.setPic(picurl);
//		appendString(dline, data.getDesc());
		ymtbean.setDesc("商品详情文描");
//		appendString(dline, data.getDesc_pic());
		ymtbean.setDesc_pic(picurl);
//		appendString(dline, data.getCatalog_type1());
		ymtbean.setCatalog_type1("颜色");
//		appendString(dline, data.getCatalog_type1_value());
		ymtbean.setCatalog_type1_value("红色;蓝色;橙色;");
//		appendString(dline, data.getCatalog_type2());
		ymtbean.setCatalog_type2("尺码");
//		appendString(dline, data.getCatalog_type2_value());
		ymtbean.setCatalog_type2_value("S;M;L;XL");
//		appendString(dline, data.getCatalog_type2());
		ymtbean.setPrice("1;2;3;4;5;6;7;8;9;10;11;12");
//		appendString(dline, data.getPrice());
		ymtbean.setStock("11;12;13;14;15;16;17;18;19;110;111;112");
//		appendString(dline, data.getStock());
		ymtbean.setSku("sku1;sku2");
//		appendString(dline, data.getSku());
		ymtbean.setProductcode(TestDataManager.getRandomUUID().toString());
//		appendString(dline, data.getProductcode());
		ymtbean.setBrandid("AddAgentProductCallService.BrandId");
//		appendString(dline, data.getBrandid());
		ymtbean.setThird_categoryid("1003");
//		appendString(dline, data.getThird_categoryid());
		ymtbean.setLogistics_modeid("999");
//		appendString(dline, data.getLogistics_modeid());
		ymtbean.setIdcard_form("1");
//		appendString(dline, data.getIdcard_form());
		return ymtbean;
	}
	/**
	 * YMT格式导入数据单规格数据
	 * @param title
	 * @param picurl
	 * @return
	 */
	public static YMTExportBean initOneYMTExportBean(String title, String picurl) {
		YMTExportBean ymtbean = new YMTExportBean();
//		appendString(dline, data.getTitle());
		ymtbean.setTitle(title);
//		appendString(dline, data.getPic());
		ymtbean.setPic(picurl);
//		appendString(dline, data.getDesc());
		ymtbean.setDesc("商品详情文描");
//		appendString(dline, data.getDesc_pic());
		ymtbean.setDesc_pic(picurl);
//		appendString(dline, data.getCatalog_type1());
		ymtbean.setCatalog_type1("颜色");
//		appendString(dline, data.getCatalog_type1_value());
		ymtbean.setCatalog_type1_value("红色");
//		appendString(dline, data.getCatalog_type2());
		ymtbean.setCatalog_type2("尺码");
//		appendString(dline, data.getCatalog_type2_value());
		ymtbean.setCatalog_type2_value("S");
//		appendString(dline, data.getCatalog_type2());
		ymtbean.setPrice("1");
//		appendString(dline, data.getPrice());
		ymtbean.setStock("11");
//		appendString(dline, data.getStock());
		ymtbean.setSku("sku1");
//		appendString(dline, data.getSku());
		ymtbean.setProductcode(TestDataManager.getRandomUUID().toString());
//		appendString(dline, data.getProductcode());
		ymtbean.setBrandid("AddAgentProductCallService.BrandId");
//		appendString(dline, data.getBrandid());
		ymtbean.setThird_categoryid("1003");
//		appendString(dline, data.getThird_categoryid());
		ymtbean.setLogistics_modeid("1");
//		appendString(dline, data.getLogistics_modeid());
		ymtbean.setIdcard_form("1");
//		appendString(dline, data.getIdcard_form());
		return ymtbean;
	}
	/**
	 * * 初始化导入商品信息 setDescription html文描
	 * 
	 * @param title
	 *            标题
	 * @param price
	 *            价格
	 * @param num
	 *            库存数量
	 * @return
	 */
	public static TaobaoZhuShouExportBean initTaobaoZhuShouExportBean(String title, String price, Integer num,String picurl) {
		TaobaoZhuShouExportBean tb = new TaobaoZhuShouExportBean();
		tb.setTitle("\"" + title + "\"");
		tb.setCid(TestDataManager.getRandomIntNum(8));
		tb.setSeller_cids("");
		tb.setStuff_status(3);
		tb.setLocation_state("\"上海\"");
		tb.setLocation_city("\"上海\"");
		tb.setItem_type(1);
		tb.setPrice(price);
		tb.setAuction_increment("\"\"");
		tb.setNum(num);
		tb.setValid_thru("0");
		tb.setFreight_payer("0");
		tb.setPost_fee("1.15611e+25");
		tb.setEms_fee("9.69783e-38");
		tb.setExpress_fee("0");
		tb.setHas_invoice(0);
		tb.setHas_warranty(0);
		tb.setApprove_status(2);
		tb.setHas_showcase(0);
		tb.setList_time("\"" + YMTDateUtil.getBeforeOrNextSecond(100, "yyyy-MM-dd HH:mm:ss ") + "\"");
		tb.setDescription("\"<p><img style=\"\"max-width:750.0px;\"\" align=\"\"absmiddle\"\" src=\"\""+picurl+"\"\">\"</p>");
		// 规格信息？
		tb.setCateProps(
				"\"20000:114120764;20019:947486781;20105:103646;121516899:90624;152600940:50288;152608881:27426639;152628860:10122;152646843:29816;152656772:124993;220785519:21959;5919063:6536025;152612936:89486051;1627207:28321;1627207:28332\"");
		tb.setPostage_id("23545441780");
		tb.setHas_discount(0);
		tb.setModified("\"" + YMTDateUtil.getBeforeOrNextSecond(-100, "yyyy-MM-dd HH:mm:ss ") + "\"");
		tb.setUpload_fail_msg("\"错误信息: 您没开店，不能在此类目下发布宝贝;\"");
		tb.setPicture_status("\"2;2;2;\"");
		tb.setAuction_point("0");
		// 图片规则？
		tb.setPicture("48a02a9f4e24d86a4e02cbcf46bf22b7:1:0:|"+picurl+";135de0256c1c8adb864a18935d27ad39:2:0:1627207:28332|"+picurl+";fafa5efeaf3cbe3b23b2748d13e629a1:2:0:1627207:28321|"+picurl+";");
		tb.setVideo("");
		// 规格价格库存
		tb.setSkuProps("100:1::5919063:6536025;152612936:89486051;1627207:28321;99:1::5919063:6536025;152612936:89486051;1627207:28332;");
		tb.setInputPids("20000,152646947");
		tb.setInputValues("品牌;型号*;,规格");
		tb.setOuter_id("");
		tb.setPropAlias("");
		tb.setAuto_fill(0);
		tb.setNum_id("0");
		tb.setLocal_cid("-1");
		tb.setNavigation_type(1);
		tb.setUser_name("");
		tb.setSyncStatus(2);
		tb.setIs_lighting_consigment("195");
		tb.setIs_xinpin("224");
		tb.setFoodparame("product_date_end:;product_date_start:;stock_date_end:;stock_date_start:");
		tb.setFeatures("mysize_tp:0");
		tb.setBuyareatype("0");
		tb.setGlobal_stock_type("-1");
		tb.setGlobal_stock_country("");
		tb.setSub_stock_type(num);
		tb.setItem_size("bulk:0.300000");
		tb.setItem_weight("1.000");
		tb.setSell_promise(0);
		tb.setCustom_design_flag("");
		tb.setWireless_desc("\"<wapDesc><img>"+picurl+"</img></wapDesc>\"");
		tb.setBarcode(";");
		tb.setSku_barcode("0");
		tb.setNewprepay(0);
		tb.setSubtitle("\"宝贝卖点\"");
		tb.setCpv_memo("\"\"");
		tb.setInput_custom_cpv("\"\"");
		tb.setQualification("\"%7B%20%20%7D\"");
		tb.setAdd_qualification(0);
		tb.setO2o_bind_service(0);
		tb.setTmall_extend("");
		tb.setProduct_combine("");
		tb.setTmall_item_prop_combine("");
		tb.setTaoschema_extend("");
		return tb;
	}

	/**
	 * 创建淘宝导出商品文件 越洋店铺导入用
	 */
	public static void CreateTaoBaoExportFile(String outputfilename, List<TaobaoZhuShouExportBean> datas) throws Exception {
		List<String> fileinfo = new ArrayList<String>();
		String line1 = "version 1.00";
		// TestDataManager.appendFileToLine(outputfilename,
		// line1,StandardCharsets.UTF_16LE.toString());
		String line2 = "title	cid	seller_cids	stuff_status	location_state	location_city	item_type	price	auction_increment	num	valid_thru	freight_payer	post_fee	ems_fee	express_fee	has_invoice	has_warranty	approve_status	has_showcase	list_time	description	cateProps	postage_id	has_discount	modified	upload_fail_msg	picture_status	auction_point	picture	video	skuProps	inputPids	inputValues	outer_id	propAlias	auto_fill	num_id	local_cid	navigation_type	user_name	syncStatus	is_lighting_consigment	is_xinpin	foodparame	features	buyareatype	global_stock_type	global_stock_country	sub_stock_type	item_size	item_weight	sell_promise	custom_design_flag	wireless_desc	barcode	sku_barcode	newprepay	subtitle	cpv_memo	input_custom_cpv	qualification	add_qualification	o2o_bind_service	tmall_extend	product_combine	tmall_item_prop_combine	taoschema_extend";
		// TestDataManager.appendFileToLine(outputfilename,
		// line2,StandardCharsets.UTF_16LE.toString());
		String line3 = "宝贝名称	宝贝类目	店铺类目	新旧程度	省	城市	出售方式	宝贝价格	加价幅度	宝贝数量	有效期	运费承担	平邮	EMS	快递	发票	保修	放入仓库	橱窗推荐	开始时间	宝贝描述	宝贝属性	邮费模版ID	会员打折	修改时间	上传状态	图片状态	返点比例	新图片	视频	销售属性组合	用户输入ID串	用户输入名-值对	商家编码	销售属性别名	代充类型	数字ID	本地ID	宝贝分类	用户名称	宝贝状态	闪电发货	新品	食品专项	尺码库	采购地	库存类型	国家地区	库存计数	物流体积	物流重量	退换货承诺	定制工具	无线详情	商品条形码	sku 条形码	7天退货	宝贝卖点	属性值备注	自定义属性值	商品资质	增加商品资质	关联线下服务	tmall扩展字段	产品组合	tmall属性组合	taoschema扩展字段";
		// TestDataManager.appendFileToLine(outputfilename,
		// line3,StandardCharsets.UTF_16LE.toString());
		fileinfo.add(line1);
		fileinfo.add(line2);
		fileinfo.add(line3);
		datas.forEach(data -> {
			// "title cid seller_cids stuff_status location_state location_city
			// item_type price auction_increment num valid_thru freight_payer
			// post_fee ems_fee express_fee has_invoice has_warranty
			// approve_status has_showcase list_time description cateProps
			// postage_id has_discount modified upload_fail_msg picture_status
			// auction_point picture video skuProps inputPids inputValues
			// outer_id propAlias auto_fill num_id local_cid navigation_type
			// user_name syncStatus is_lighting_consigment is_xinpin foodparame
			// features buyareatype global_stock_type global_stock_country
			// sub_stock_type item_size item_weight sell_promise
			// custom_design_flag wireless_desc barcode sku_barcode newprepay
			// subtitle cpv_memo input_custom_cpv qualification
			// add_qualification o2o_bind_service tmall_extend product_combine
			// tmall_item_prop_combine taoschema_extend"
			// StringBuffer dline=data.getTitle()+" "+data.getCid()+"
			// "+data.getSeller_cids()+;
			StringBuffer dline = new StringBuffer();
			try {
				appendString(dline, data.getTitle());
				appendString(dline, data.getCid());
				appendString(dline, data.getSeller_cids());
				appendString(dline, data.getStuff_status());
				appendString(dline, data.getLocation_state());
				appendString(dline, data.getLocation_city());
				appendString(dline, data.getItem_type());
				appendString(dline, data.getPrice());
				appendString(dline, data.getAuction_increment());
				appendString(dline, data.getNum());
				appendString(dline, data.getValid_thru());
				appendString(dline, data.getFreight_payer());
				appendString(dline, data.getPost_fee());
				appendString(dline, data.getEms_fee());
				appendString(dline, data.getExpress_fee());
				appendString(dline, data.getHas_invoice());
				appendString(dline, data.getHas_warranty());
				appendString(dline, data.getApprove_status());
				appendString(dline, data.getHas_showcase());
				appendString(dline, data.getList_time());
				appendString(dline, data.getDescription());
				appendString(dline, data.getCateProps());
				appendString(dline, data.getPostage_id());
				appendString(dline, data.getHas_discount());
				appendString(dline, data.getModified());
				appendString(dline, data.getUpload_fail_msg());
				appendString(dline, data.getPicture_status());
				appendString(dline, data.getAuction_point());
				appendString(dline, data.getPicture());
				appendString(dline, data.getVideo());
				appendString(dline, data.getSkuProps());
				appendString(dline, data.getInputPids());
				appendString(dline, data.getInputValues());
				appendString(dline, data.getOuter_id());
				appendString(dline, data.getPropAlias());
				appendString(dline, data.getAuto_fill());
				appendString(dline, data.getNum_id());
				appendString(dline, data.getLocal_cid());
				appendString(dline, data.getNavigation_type());
				appendString(dline, data.getUser_name());
				appendString(dline, data.getSyncStatus());
				appendString(dline, data.getIs_lighting_consigment());
				appendString(dline, data.getIs_xinpin());
				appendString(dline, data.getFoodparame());
				appendString(dline, data.getFeatures());
				appendString(dline, data.getBuyareatype());
				appendString(dline, data.getGlobal_stock_type());
				appendString(dline, data.getGlobal_stock_country());
				appendString(dline, data.getSub_stock_type());
				appendString(dline, data.getItem_size());
				appendString(dline, data.getItem_weight());
				appendString(dline, data.getSell_promise());
				appendString(dline, data.getCustom_design_flag());
				appendString(dline, data.getWireless_desc());
				appendString(dline, data.getBarcode());
				appendString(dline, data.getSku_barcode());
				appendString(dline, data.getNewprepay());
				appendString(dline, data.getSubtitle());
				appendString(dline, data.getCpv_memo());
				appendString(dline, data.getInput_custom_cpv());
				appendString(dline, data.getQualification());
				appendString(dline, data.getAdd_qualification());
				appendString(dline, data.getO2o_bind_service());
				appendString(dline, data.getTmall_extend());
				appendString(dline, data.getProduct_combine());
				appendString(dline, data.getTmall_item_prop_combine());
				appendString(dline, data.getTaoschema_extend());
				fileinfo.add(dline.toString());
				TestDataManager.writeToFile(outputfilename, fileinfo, StandardCharsets.UTF_16LE);
			} catch (Exception e) {
				e.printStackTrace();
			}
		});

	}
	/**
	 * 创建一个默认的ymt 导入文件 自动填入默认数据
	 * @return
	 * m.put("file", fileurl);
        m.put("param", List<YMTExportBean>);
        m.put("md5", TestDataManager.getFileMD5(uploadfile));
	 * @throws Exception
	 */
	public static Map<String, Object> CreateDefYmtExportFile() throws Exception {
		String f1 = System.getProperty("user.dir") + File.separator
				+ "resource" + File.separator + "1.jpg";
    	String picUrl= TestDataManager.UploadFile(f1);
    	String f2 = System.getProperty("user.dir") + File.separator
				+ "resource" + File.separator + "upload.bmp";
    	picUrl+=";"+ TestDataManager.UploadFile(f2);
//        String picUrl = "http://pc1.img.ymatou.com/G01/shangou/M00/2C/D0/rBBlD1gHOV6AY32AAAEN6UG5TOc701_400_401_n_w_l.jpg";
        YMTExportBean ymtb = ProductManagerCallServiceV3.initYMTExportBean("淘宝商品",picUrl);
        List<YMTExportBean> datas = Arrays.asList(ymtb);
     // 随机产物名
		String tname = YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMddHHmmSS");
		ProductManagerCallServiceV3.CreateYMTExportFile(tname + ".csv", datas);
		// tmp\ymd\ --产物目录
		String tmpfd = "temp" + File.separatorChar + tname + File.separatorChar;
		TestDataManager.MoveFile(tname + ".csv", tmpfd);
		String uploadfile=tmpfd+ File.separatorChar+tname + ".csv";
        String upl= TestDataManager.UploadFile(uploadfile);
        Map m=new HashMap<String, Object>();
        m.put("file", upl);
        m.put("param", datas);
        m.put("md5", TestDataManager.getFileMD5(uploadfile));
        return m;
	}
	
	/**
	 * 创建一个默认的excel 导入文件 自动填入默认数据
	 * @return
	 * m.put("file", fileurl);
        m.put("param", List<YMTExportBean>);
        m.put("md5", TestDataManager.getFileMD5(uploadfile));
	 * @throws Exception
	 */
	public static Map<String, Object> CreateExcelExportFile() throws Exception {
		String f1 = System.getProperty("user.dir") + File.separator
				+ "resource" + File.separator + "1.jpg";
    	String picUrl= TestDataManager.UploadFile(f1);
    	String f2 = System.getProperty("user.dir") + File.separator
				+ "resource" + File.separator + "upload.bmp";
    	picUrl+=";"+ TestDataManager.UploadFile(f2);
    	
        YMTExportBean ymtb = ProductManagerCallServiceV3.initYMTExportBean("淘宝商品",picUrl);
        List<YMTExportBean> datas = Arrays.asList(ymtb);
     // 随机产物名
		String tname = YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMddHHmmSS");
		ProductManagerCallServiceV3.CreateYMTExportFile(tname + ".csv", datas);
		// tmp\ymd\ --产物目录
		String tmpfd = "temp" + File.separatorChar + tname + File.separatorChar;
		TestDataManager.MoveFile(tname + ".csv", tmpfd);
		String uploadfile=tmpfd+ File.separatorChar+tname + ".csv";
        String upl= TestDataManager.UploadFile(uploadfile);
        Map m=new HashMap<String, Object>();
        m.put("file", upl);
        m.put("param", datas);
        m.put("md5", TestDataManager.getFileMD5(uploadfile));
        return m;
	}
	/**
	 * 创建ymt导入文件
	 * @param outputfilename 输出文件
	 * @param datas 输入结构
	 * @throws Exception
	 */
	public static void CreateYMTExportFile(String outputfilename, List<YMTExportBean> datas) throws Exception {
		List<String> fileinfo = new ArrayList<String>();
		String line1 = "title	pic	desc	desc_pic	catalog_type1	catalog_type1_value	catalog_type2	catalog_type2_value	price	stock	sku	productcode	brandid	third_categoryid	logistics_modeid	idcard_form	tariff_rate";
		fileinfo.add(line1);
		String line2 = "商品名称（必填）	商品主图（必填）	商品详情文描	商品详情图片	规格类型1	规格类型1属性值	规格类型2	规格类型2属性值	商品价格	商品库存	商家商品编码	内部系统的商品ID（必填）	品牌ID	三级类目ID	物流方式ID	身份证形式	税率";
		fileinfo.add(line2);
		datas.forEach(data -> {
			StringBuffer dline = new StringBuffer();
			try {
				appendString(dline, data.getTitle());
				appendString(dline, data.getPic());
				appendString(dline, data.getDesc());
				appendString(dline, data.getDesc_pic());
				appendString(dline, data.getCatalog_type1());
				appendString(dline, data.getCatalog_type1_value());
				appendString(dline, data.getCatalog_type2());
				appendString(dline, data.getCatalog_type2_value());
				appendString(dline, data.getPrice());
				appendString(dline, data.getStock());
				appendString(dline, data.getSku());
				appendString(dline, data.getProductcode());
				appendString(dline, data.getBrandid());
				appendString(dline, data.getThird_categoryid());
				appendString(dline, data.getLogistics_modeid());
				appendString(dline, data.getIdcard_form());
				appendString(dline, data.getTariff_rate());
				if(data.getTitle()==null||data.getTitle().equals("")) {
					dline.insert(0, "	");
				}
				fileinfo.add(dline.toString());
			} catch (Exception e) {
				e.printStackTrace();
			}
		});
		TestDataManager.writeToFile(outputfilename, fileinfo, StandardCharsets.UTF_16LE);
	}
	/**
	 * 同步mongo
	 * @param productId
	 * @param ActionType, 默认是同步创建商品
	 * @param activityId 活动Id，如果没有活动，activityId为0
	 * @throws ClientProtocolException
	 * @throws IOException
	 * 可用参数 ： "CreateProduct"
	 */
	public static void productMongocrudSync(String productId,String actionType,Integer activityId) throws ClientProtocolException, IOException
	{
		MongocrudBean bean=new MongocrudBean();
		MongocrudCall call=new MongocrudCall();
		if(actionType==null){
			bean.setActionType("CreateProduct");
		}else{
			bean.setActionType(actionType);
		}
		bean.setActivityId(activityId);
		bean.setProductId(productId);
		bean.setTransactionId(TestDataManager.getRandomIntNum(9));
		call.setData(bean);
		call.callService();
	}
	
	/**
	 * 同步es
	 * @param productId
	 * @param ActionType 默认是同步创建商品
	 * @param activityId 若不是活动商品，activityId=0
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void productEsSync(String productId,String actionType,int activityId) throws ClientProtocolException, IOException
	{
		ESBean esBean=new ESBean();
		ESCall escall=new ESCall();
		//同步es
		esBean.setActivityId(activityId);
		if(actionType==null){
			esBean.setActionType("CreateProduct");
		}else{
			esBean.setActionType(actionType);
		}
		
		esBean.setProductId(productId);
		esBean.setTransactionId(TestDataManager.getRandomIntNum(5));
		escall.setData(esBean);
		escall.callService();
	}
	private static void appendString(StringBuffer dline, Object data) throws Exception {
		if(data==null) {
			data="";
		}
		if (dline.length() == 0) {
			dline.append(data.toString());
		} else {
			dline.append("	" + data.toString());
		}
	}

	/**
	 * 创建淘宝导入文件zip包
	 * @param datas
	 * @return
	 * @throws Exception
	 */
	public static String CreateTaoBaoExportZipFile(List<TaobaoZhuShouExportBean> datas) throws Exception {
		// 随机产物名
		String tname = YMTDateUtil.getBeforeOrNextDay(0, "yyyyMMddHHmmSS");
		ProductManagerCallServiceV3.CreateTaoBaoExportFile(tname + ".csv", datas);
		// tmp\ymd\ --产物目录
		String tmpfd = "temp" + File.separatorChar + tname + File.separatorChar;
		// tmp\ymd\ymd\ --图片目录
		String tmppicfd = tmpfd + tname + File.separatorChar;
		// 源图片目录
		String srcpicfd = "resource" + File.separatorChar + "taobaoImport" + File.separatorChar;
		TestDataManager.MoveFile(tname + ".csv", tmpfd);
		TestDataManager.FileCopy(srcpicfd + "135de0256c1c8adb864a18935d27ad39.tbi", tmppicfd);
		TestDataManager.FileCopy(srcpicfd + "48a02a9f4e24d86a4e02cbcf46bf22b7.tbi", tmppicfd);
		TestDataManager.FileCopy(srcpicfd + "fafa5efeaf3cbe3b23b2748d13e629a1.tbi", tmppicfd);
		String zipfile = "temp" + File.separatorChar + tname + ".zip";
		ZipUtils.zipFiles(tmpfd, zipfile);
		return tname;
	}
	/**
	 * 批量修改平台佣金
	 * @
	 */
	public static void UpdateProductCommision(int sellerId,String productId,String sellerName,BigDecimal commission) throws IOException {
		UpdateProductCommisionBean updateProductCommisionBean = new UpdateProductCommisionBean();
		UpdateProductCommisionCall updateProductCommisionCall = new UpdateProductCommisionCall();
		updateProductCommisionBean.setCommission(commission);
		updateProductCommisionBean.setSellerName(sellerName);
		updateProductCommisionBean.setProductId(productId);
		updateProductCommisionBean.setUserId(sellerId);
		updateProductCommisionCall.setData(updateProductCommisionBean);
		updateProductCommisionCall.callService();
	}
	public static void main(String[] args) throws Exception {
		// OrderdeliveryBean sellerAllocationBean = new OrderdeliveryBean();
		// sellerAllocationBean.setSellerId(288484);
		// OrderdeliveryCall sellerAllocationCall = new OrderdeliveryCall();
		// sellerAllocationCall.setData(sellerAllocationBean);
		// sellerAllocationCall.callService();
		TaobaoZhuShouExportBean tb = ProductManagerCallServiceV3.initTaobaoZhuShouExportBean("淘宝商品", "12.00", 50,"http://staticontent.ymatou.com/html/20150825dl/dl_02.jpg");
		TaobaoZhuShouExportBean tb2 = ProductManagerCallServiceV3.initTaobaoZhuShouExportBean("淘宝商品2", "13.00", 10,"http://staticontent.ymatou.com/html/20150825dl/dl_02.jpg");
		
		List<TaobaoZhuShouExportBean> datas = Arrays.asList(tb,tb2);
		ProductManagerCallServiceV3.CreateTaoBaoExportZipFile(datas);
	}
	
	//批量添加商品进入安利会
		public static JsonObject BatchAddAlhProduct(int sellerId,List<String> productId) throws ClientProtocolException, IOException{
			BatchAddAlhProductCall batchAddAlhProductCall=new BatchAddAlhProductCall();
			BatchAddAlhProductBean batchaddalhproductBean=new BatchAddAlhProductBean();
			
			batchaddalhproductBean.setUserId(sellerId);
			batchaddalhproductBean.setProductIds(productId);
			batchAddAlhProductCall.setData(batchaddalhproductBean);
			batchAddAlhProductCall.callService();
			return batchAddAlhProductCall.getJsonObject();
		}
		
		
		//添加商品进入安利会
		public static JsonObject BatchAddAlhProduct(int sellerId,String productId) throws ClientProtocolException, IOException{
			BatchAddAlhProductCall batchAddAlhProductCall=new BatchAddAlhProductCall();
			BatchAddAlhProductBean batchaddalhproductBean=new BatchAddAlhProductBean();
			
			batchaddalhproductBean.setUserId(sellerId);
			batchaddalhproductBean.setProductIds(Arrays.asList(productId));
			batchAddAlhProductCall.setData(batchaddalhproductBean);
			batchAddAlhProductCall.callService();
			return batchAddAlhProductCall.getJsonObject();
		}
		
		
		//停止安利会商品推广
		public static JsonObject BatchStopAlhProduct(int sellerId,String productId) throws ClientProtocolException, IOException{
			BatchStopAlhProductCall batchStopAlhProductCall = new BatchStopAlhProductCall();
			BatchStopAlhProductBean batchStopAlhProductBean = new BatchStopAlhProductBean();
			
			batchStopAlhProductBean.setUserId(sellerId);
			batchStopAlhProductBean.setProductIds(Arrays.asList(productId));
			batchStopAlhProductCall.setData(batchStopAlhProductBean);
			batchStopAlhProductCall.callService();
			return batchStopAlhProductCall.getJsonObject();
		}
		
		
		//批量停止安利会推广
		public static JsonObject BatchStopAlhProduct(int sellerId,List<String> productIds) throws ClientProtocolException, IOException{
			BatchStopAlhProductCall batchStopAlhProductCall = new BatchStopAlhProductCall();
			BatchStopAlhProductBean batchStopAlhProductBean = new BatchStopAlhProductBean();
			
			batchStopAlhProductBean.setUserId(sellerId);
			batchStopAlhProductBean.setProductIds(productIds);
			batchStopAlhProductCall.setData(batchStopAlhProductBean);
			batchStopAlhProductCall.callService();
			return batchStopAlhProductCall.getJsonObject();
		}
		
		
	//设置安利会费率
	public static JsonObject SetAlhProductRebateRate(int userId,String productId,BigDecimal rebateRate) throws ClientProtocolException, IOException{
		SetAlhProductRebateRateBean setAlhProductRebateRateBean = new SetAlhProductRebateRateBean();
		SetAlhProductRebateRateCall setAlhProductRebateRateCall = new SetAlhProductRebateRateCall();
		
		setAlhProductRebateRateBean.setProductId(productId);
		setAlhProductRebateRateBean.setUserId(userId);
		setAlhProductRebateRateBean.setRebateRate(rebateRate);
		setAlhProductRebateRateCall.setData(setAlhProductRebateRateBean);
		setAlhProductRebateRateCall.callService();
		return setAlhProductRebateRateCall.getJsonObject();
	}

	
	
	
	/**
	 * 同步mongo-创建商品
	 * @param productId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void createProduct_sync(String productId) throws ClientProtocolException, IOException
	{
		MongocrudBean bean =new MongocrudBean();
		MongocrudCall call=new MongocrudCall();
		
		bean.setActionType("CreateProduct");
		bean.setActivityId(0);
		bean.setProductId(productId);
		bean.setTransactionId(TestDataManager.getRandomIntNum(9));
		call.setData(bean);
		call.callService();
	}
	
	/**
	 * 同步es-创建商品
	 * @param productId
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void createProduct_synces(String productId) throws ClientProtocolException, IOException
	{
		ESBean bean =new ESBean();
		ESCall call=new ESCall();
		
		bean.setActionType("CreateProduct");
		bean.setActivityId(0);
		bean.setProductId(productId);
		bean.setTransactionId(TestDataManager.getRandomIntNum(9));
		call.setData(bean);
		call.callService();
	}
}
